<%--
  Created by IntelliJ IDEA.
  User: lml
  Date: 2022/10/24
  Time: 17:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui-v2.7.6/layui/css/layui.css" >
</head>
<body>
<form class="layui-form" action=""  id="saveUserForm" <%--style="display: none"--%>  lay-filter="updateUserFormFilter">
    <input type="hidden" name="id" >

    <form class="layui-form" enctype="multipart/form-data" action="" >

        <div class="registerbox-title">用户注册中心</div>
        <div class="layui-form-item">
            <div class="layui-form-item pass" >
                <label class="layui-form-label">用户id</label>
                <div class="layui-input-inline">
                    <input type="text" name="id" autocomplete="off" disabled="none"
                           class="layui-input" id="id" value="${user.id}">
                </div>
            </div>
            <label class="layui-form-label">用户账号</label>
            <div class="layui-input-inline">
                <input type="text" name="username" id="username"  disabled="none" lay-verify="required" placeholder="请输入账号" autocomplete="off"
                       class="layui-input" value="${user.username}">
            </div>
        </div>

        <div class="layui-form-item pass" >
            <label class="layui-form-label">用户密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password"  lay-verify="required" onblur="mimajianca()" placeholder="请输入密码" autocomplete="off"
                       class="layui-input" id="pass1">
            </div>
        </div>
        <div class="layui-form-item pass" >
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password"  lay-verify="required" placeholder="请输入新密码"
                       autocomplete="off" class="layui-input" id="pass2">
            </div>
        </div>

        <div class="layui-form-item pass" >
            <label class="layui-form-label">确认新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password"  lay-verify="required|pass" placeholder="请再次输入新密码"
                       autocomplete="off" class="layui-input" id="pass3">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formSaveUser">修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</form>
<script src="${pageContext.request.contextPath}/static/layui-v2.7.6/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery-3.6.1.min.js"></script>
<script>
var passwordStatus=true;
    $(function () {


        layui.use(['table','layer','form','jquery'], function(){
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.jquery;
            var upload = layui.upload
                , element = layui.element;
            var namestatus=true;

            // // 自定义校验  验证两次密码是不是一样
            form.verify({
                pass: function(value){ //自定义lay-verify的昵称，value：表单的值
                    var pass2 = $("#pass2").val();
                    if(value!=pass2){
                        return "两次密码不一致！！！";
                    }

                }
            });


            //提交表单
            // Layui提交表单 监听提交  data代表的是form表单里面的所有的内容
            form.on('submit(formSaveUser)', function(data){
                var id=$("#id").val();
                var username=$("#username").val();
                var password=$("#pass3").val();
                var params = {};
                params.id=id;
                params.username=username;
                params.password=password;
                namestatus=passwordStatus;
                if(namestatus){
                    $.ajax({
                        url:"${pageContext.request.contextPath}/editpassword",
                        type:"post",
                        dataType:"JSON",
                        data:params,//表单里所有数据
                        success:function (ret){
                            if (ret.data == "修改成功"){
                                layer.msg("修改成功",{icon:"1"});
                                /*window.location="${pageContext.request.contextPath}/view/login.jsp"*/
                            }
                        }
                    })
                }
                return false;
            })


        })
    })
function mimajianca(){
    var username=$("#username").val();
    var password=$("#pass1").val();
    var params = {};
    params.username=username;
    params.password=password;

    $.ajax({
        url:"${pageContext.request.contextPath}/login",
        type:"post",
        dataType:"JSON",
        data:params,//表单里所有数据
        success:function (ret){
            if (ret.data == false){
                layer.msg("密码不正确",{icon:"1"});
                passwordStatus=false;
                //关闭所有弹框
            }
        }
    })
}
</script>
</body>
</html>
